<template>
  <div class="accordion-container">
    <div class="accordion-item" 
      v-for="(item, index) in menuItems" 
      :key="index"
      :class="{ active: activeIndex === index }"
      @mouseenter="activeIndex = index"
    >
      <div class="accordion-content">
        <img :src="item.image" :alt="item.title">
        <div class="overlay">
          <h3>{{ item.title }}</h3>
          <div class="sub-menu">
            <template v-for="(subItem, subIndex) in item.children" :key="subIndex">
              <a 
                v-if="isExternalLink(subItem.path)"
                :href="subItem.path"
                target="_blank"
                class="sub-item"
              >
                {{ subItem.title }}
              </a>
              <router-link 
                v-else
                :to="subItem.path"
                class="sub-item"
              >
                {{ subItem.title }}
              </router-link>
            </template>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import productionImg from '@/assets/images/1.jpg'
import materialImg from '@/assets/images/2.jpg'
import equipmentImg from '@/assets/images/3.jpg'
import qualityImg from '@/assets/images/4.jpg'
import monitorImg from '@/assets/images/5.jpg'

const activeIndex = ref(2)

const isExternalLink = (path: string): boolean => {
  return path.startsWith('http://') || path.startsWith('https://')
}

const menuItems = [
  {
    title: 'MES下载',
    image: productionImg,
    children: [
      { title: '转网址', path: 'http://192.168.8.23/' }
    ]
  },
  {
    title: '物料管理',
    image: materialImg,
    children: [
      { title: '库存查询', path: '/material/inventory' },
      { title: '物料入库', path: '/material/in' },
      { title: '物料出库', path: '/material/out' }
    ]
  },
  {
    title: 'MES相关',
    image: equipmentImg,
    children: [
    { title: 'MES对话', path: '/production/query' },
    { title: '查询配置', path: '/production/queryConfig' }
    ]
  },
  {
    title: '质量管理',
    image: qualityImg,
    children: [
      { title: '质量检测', path: '/quality/inspection' },
      { title: '不良品管理', path: '/quality/defect' },
      { title: '质量报表', path: '/quality/report' }
    ]
  },
  {
    title: '系统监控',
    image: monitorImg,
    children: [
      { title: '实时监控', path: '/monitor/realtime' },
      { title: '报警信息', path: '/monitor/alarm' },
      { title: '系统日志', path: '/monitor/log' }
    ]
  }
]
</script>

<style scoped lang="scss">
.accordion-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: fixed;
  left: 0;
  top: 0;
  gap: 0;
  background: #000;
}

.accordion-item {
  position: relative;
  flex: 1;
  height: 100vh;
  overflow: hidden;
  transition: flex 0.6s ease;
  cursor: pointer;

  // 默认状态下的遮罩层和标题
  .overlay {
    opacity: 0;
    h3 {
      opacity: 0;
    }
    .sub-menu {
      opacity: 0;
    }
  }

  // 中间三个面板的图片位置调整
  &:nth-child(2),
  &:nth-child(3),
  &:nth-child(4) {
    .accordion-content {
      img {
        object-position: center;
      }
    }
  }

  // 第一个面板特殊处理
  &:first-child {
    .accordion-content {
      img {
        object-position: left center;
      }
    }
  }

  // 最后一个面板特殊处理
  &:last-child {
    .accordion-content {
      img {
        object-position: right center;
      }
    }
  }

  &.active {
    flex: 3;

    .accordion-content {
      transform: scale(1.1);
    }

    .overlay {
      opacity: 1;
      background: rgba(0, 0, 0, 0.5);

      h3 {
        transform: translateY(0);
        opacity: 1;
      }

      .sub-menu {
        opacity: 1;
        transform: translateY(0);
      }
    }
  }

  &:not(.active) {
    flex: 0.5;

    .accordion-content {
      transform: scale(1);
    }

    .overlay {
      opacity: 0;
      
      h3, .sub-menu {
        opacity: 0;
        transform: translateY(20px);
      }
    }
  }
}

.accordion-content {
  position: absolute;
  inset: 0;
  transition: transform 0.6s ease;
  transform-origin: center;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: object-position 0.6s ease;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  transition: all 0.6s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  h3 {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 2rem;
    transform: translateY(-20px);
    transition: all 0.6s ease;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  }

  .sub-menu {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.6s ease;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .sub-item {
    color: white;
    text-decoration: none;
    padding: 1rem 2rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.15);
    transition: all 0.3s ease;
    font-size: 1.2rem;
    letter-spacing: 1px;

    &:hover {
      background: rgba(255, 255, 255, 0.3);
      transform: translateY(-2px);
    }
  }
}
</style>
